home *** CD-ROM | disk | FTP | other *** search
- /* from
- Freeware (C) Thomas Radtke 1996
- revision: 31.03.1996
- */
-
- #include <dos/dos.h>
- #include <dos/var.h>
-
- #ifndef HAVE_XMALLOC
- int xmalloc(int size)
- {
- int retval;
-
- if (!(retval=malloc(size))) {
- printf("can't allocate %d bytes\n");
- exit(20);
- }
- return retval;
- }
- #endif /* HAVE_XMALLOC */
-
- char row_var[100],col_var[5],*col_item[1024],arg_buffer[1024],command[1024];
-
- main(int argc,char **argv)
- {
- struct FileHandle *fh_in=0;
- int file=1,i,j,row=0;
-
- if (argc<3) {
- printf("syntax: %s <list|-> <command> [{args}]\n",*argv);
- exit(20);
- }
-
- strcpy(command,argv[2]);
- for (j=3; j<argc; j++)
- {
- strcat(command," ");
- strcat(command,argv[j]);
- }
-
- if (!strcmp(argv[1],"-"))
- {
- fh_in=(struct FileHandle *)Input();
- FGets(fh_in,arg_buffer,1024);
- file=0;
- }
- else if (!(fh_in=(struct FileHandle *)Open(argv[1],MODE_OLDFILE)))
- {
- printf("can't open %s\n",argv[1]);
- exit(20);
- }
- SetVar("0",argv[2],1+strlen(argv[2]),GVF_LOCAL_ONLY);
- while (1)
- {
- if (!FGets(fh_in,arg_buffer,1024)) break;
- j=0;
- for (i=0; i<1024; i++)
- {
- sprintf(col_var,"%d",i+1);
- col_item[i]=(char *)xmalloc(1024);
- if (sscanf(&arg_buffer[j],"%s",col_item[i])==-1) break;
- while (arg_buffer[j]<33 && arg_buffer[j]>0) j++;
- j+=strlen(col_item[i]);
- while (arg_buffer[j]<33 && arg_buffer[j]>0) j++;
- SetVar(col_var,col_item[i],1+strlen(col_item[i]),GVF_LOCAL_ONLY);
- }
- sprintf(row_var,"%d",row);
- SetVar("row",row_var,1+strlen(row_var),GVF_LOCAL_ONLY);
- Execute(command,0,0);
- DeleteVar("row",GVF_LOCAL_ONLY);
- for (j=0; j<i; j++)
- {
- sprintf(col_var,"%d",j+1);
- DeleteVar(col_var,GVF_LOCAL_ONLY);
- free(col_item[j]);
- }
- row++;
- }
- DeleteVar("0",GVF_LOCAL_ONLY);
- if (file) Close(fh_in);
- exit(0);
- }
-